<template>
  <avue-input-map :params="params" :placeholder="placeholder" v-model="values"></avue-input-map>
</template>

<script>
export default {
  props: {
    value: {
      type: Array,
      default: () => []
    },
    params: {
      type: Object,
      default: () => ({
        zoom: 10,
        zoomEnable: true,
        dragEnable: false
      })
    },
    placeholder: {
      type: String,
      default: '请选择地图'
    }
  },
  data() {
    return {
      values: []
    };
  },
  watch: {
    value(val) {
      this.values = val.length ? val : [];
    },
    values(val) {
      if (val.length && val !== this.value) {
        const [lng, lat, addr] = val;
        console.log(`经度: ${lng}, 纬度: ${lat}, 地址: ${addr}`);
        this.$emit('input', val);
        this.$emit('change', lng, lat, addr);
      }
    }
  }
};
</script>

<style scoped lang="scss">
.pages {
  width: 100%;
  min-height: 100vh;
}
</style>
